//
//  AddLicensePlateViewController.m
//  XinKaiFa55like
//
//  Created by junseek on 2017/8/1.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "V4AddLicensePlateViewController.h"
#import "PLTextView.h"
#import "AddImageView.h"
#import "SelectDateView.h"
#import "SelectAddressView.h"
#import "SellSelectTypeViewController.h"

#import "QPickerView.h"
#import "SelectTitleViewController.h"
#import "MyUiIAlertView.h"

@interface V4AddLicensePlateViewController ()<UITextFieldDelegate,UITextViewDelegate,SelectDateViewDelegate,SelectAddressViewDelegate>{
    UIScrollView *scrollBG;
    UITextField *txtshoujiay;//售价
    UITextField *txtMoney;//价格
    
    UITextField *txtfenlie;//分类
    UITextField *txtLevle;//等级
    UITextField *txtType;//类型
    UITextField *txtName;
    UITextField *txtcapital;//资本
    UITextField *txtCity;
//    UITextField *txtAddress;
    UITextField *txtStartDate;
    UITextField *txtEndDate;
    UITextField *txtRange;//经营范围
    PLTextView *txtadvantage;//转让优势
    AddImageView *_imageEditorV;
    
    NSInteger tempY;
    SelectDateView *dateView;
    SelectDateView *dateView2;
    
    NSString *selectDate;
    NSString *selectDateEnd;
    
    SelectAddressView *selectCity;
    NSDictionary * dicP1City;
    NSDictionary * dicP2City;
    NSDictionary * dicP3City;
    NSArray *arrayCity;
    
    NSDictionary *dicSelectLevel;
    
    int _status;
    
}
@property (nonatomic,strong)NSArray * cityList;
@property (nonatomic,strong)NSMutableArray * imageArray;
@property (nonatomic,strong)NSMutableArray * pathArray;
@property (nonatomic,strong)NSMutableArray * remArray;

@end

@implementation V4AddLicensePlateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _status=201;
    [self makeUI];
    
    
}
-(void)makeUI{
    
    
    
    scrollBG=[[UIScrollView alloc] initWithFrame:CGRectMake(0, kTopHeight, kScreenWidth, kContentHeight-44)];
    scrollBG.backgroundColor=rgbGray;
    scrollBG.autoresizingMask=UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:scrollBG];
    
    UIButton *btnSub=[RHMethods buttonWithFrame:CGRectMake(0, YH(scrollBG), kScreenWidth, 44) title:@"发布" image:nil bgimage:nil];
    [btnSub setBackgroundColor:rgbpublicColor];
    [btnSub setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnSub addTarget:self action:@selector(subButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnSub];
    
    tempY=10;
    txtshoujiay=[self addViewWithFrameY:tempY withTitle:@"售价（万元）" withSel:nil];
    tempY+=44;
    txtMoney=[self addViewWithFrameY:tempY withTitle:@"结算价格（万元）" withSel:nil];
    tempY+=44;
    txtfenlie=[self addViewWithFrameY:tempY withTitle:@"选择分类" withSel:@selector(selectfenleiButtonClicked)];
    tempY+=44;
    txtLevle=[self addViewWithFrameY:tempY withTitle:@"产品等级" withSel:@selector(selectLevleButtonClicked)];
    tempY+=44;
    txtType=[self addViewWithFrameY:tempY withTitle:@"选择类型" withSel:@selector(selectTypeButtonClicked)];
    tempY+=44;
    
    txtName=[self addViewWithFrameY:tempY withTitle:@"公司名称" withSel:nil];
    tempY+=44;
    txtcapital=[self addViewWithFrameY:tempY withTitle:@"注册资本（万元）" withSel:nil];
    tempY+=44;
    txtCity=[self addViewWithFrameY:tempY withTitle:@"注册地址" withSel:@selector(loadCityData)];
//    tempY+=44;
//    txtAddress=[self addViewWithFrameY:tempY withTitle:@"详细地址" withSel:nil];
    tempY+=44+10;
    
    
    txtStartDate=[self addViewWithFrameY:tempY withTitle:@"成立时间" withSel:@selector(selectStartDateButtonClicked)];
    tempY+=44;
    txtEndDate=[self addViewWithFrameY:tempY withTitle:@"到期时间" withSel:@selector(selectEndDateButtonClicked)];
    tempY+=44;
    txtRange=[self addViewWithFrameY:tempY withTitle:@"经营范围" withSel:nil];
    tempY+=44;
    UIView *viewBG=[[UIView alloc] initWithFrame:CGRectMake(0, tempY, kScreenWidth, 110)];
    viewBG.backgroundColor=[UIColor whiteColor];
    [scrollBG addSubview:viewBG];
    txtadvantage=[[PLTextView alloc] initWithFrame:CGRectMake(10, tempY+5, kScreenWidth-20, 100)];
    txtadvantage.delegate=self;
    txtadvantage.Placeholder=@"转让优势";
    [scrollBG addSubview:txtadvantage];
    tempY+=110;
    [self initImagesView];
    
    
    
    
    
    
    
    if ([self.userInfo isEqualToString:@"Edit"]) {
        dicSelectLevel=@{@"id":[self.otherInfo valueForJSONStrKey:@"levelid"]};
        txtName.text=[self.otherInfo valueForJSONStrKey:@"title"];
        txtMoney.text=[self.otherInfo valueForJSONStrKey:@"saleprice"];
        txtLevle.text=[self.otherInfo valueForJSONStrKey:@"levelname"];
        txtcapital.text=[self.otherInfo valueForJSONStrKey:@"regcapital"];
//        txtAddress.text=[self.otherInfo valueForJSONStrKey:@"address"];
        txtStartDate.text=[self.otherInfo valueForJSONStrKey:@"regtime"];
        txtEndDate.text=[self.otherInfo valueForJSONStrKey:@"expiretime"];
        txtRange.text=[self.otherInfo valueForJSONStrKey:@"businessscope"];
        txtadvantage.text=[self.otherInfo valueForJSONStrKey:@"advantage"];
        
        
        txtshoujiay.text=[self.otherInfo valueForJSONStrKey:@"price"];
        
        
        txtfenlie.text=[self.otherInfo valueForJSONStrKey:@"cname"];
        [txtfenlie setAddValue:[self.otherInfo valueForJSONStrKey:@"cid"] forKey:@"data"];
        txtType.text=[self.otherInfo valueForJSONStrKey:@"typename"];
        
        [txtType setAddValue:[self.otherInfo valueForJSONStrKey:@"typeid"] forKey:@"data"];
        
        txtLevle.text=[self.otherInfo valueForJSONStrKey:@"levelname"];
        
        [txtLevle setAddValue:[self.otherInfo valueForJSONStrKey:@"levelid"] forKey:@"data"];
        txtCity.text=[self.otherInfo valueForJSONStrKey:@"regaddr"];
        [txtCity setAddValue:[self.otherInfo valueForJSONStrKey:@"province"] forKey:@"province"];
        
        [txtCity setAddValue:[self.otherInfo valueForJSONStrKey:@"areaid"] forKey:@"areaid"];

        
        NSArray * pathArray = [self.otherInfo[@"path"] mutableCopy];
        self.pathArray = [[NSMutableArray alloc]initWithArray:pathArray];
        
        dicP1City=@{@"areaid":[self.otherInfo valueForJSONStrKey:@"province"],@"parentid":@"0"};
        dicP2City=@{@"areaid":[self.otherInfo valueForJSONStrKey:@"city"],@"parentid":[self.otherInfo valueForJSONStrKey:@"province"]};
        dicP3City=@{@"areaid":[self.otherInfo valueForJSONStrKey:@"area"],@"parentid":[self.otherInfo valueForJSONStrKey:@"city"]};
        txtCity.text=[self.otherInfo valueForJSONStrKey:@"regaddr"];//[NSString stringWithFormat:@"%@ %@ %@",[dicP1City valueForJSONStrKey:@"name"],[dicP2City valueForJSONStrKey:@"name"],[dicP3City valueForJSONStrKey:@"name"]];
       
//        [imageEditorV setImageUrlArray:[self.otherInfo objectForJSONKey:@"path"] imageChange:^(NSInteger suc,CGFloat h) {
//            viewS.contentSize=CGSizeMake(kScreenWidth-1, YH(imageEditorV)>H(viewS)+1?YH(imageEditorV):H(viewS)+1);
//        }];
        
        
        
        
        
    }else{
        dicSelectLevel=@{};
//        __weak UIScrollView *viewS=scrollBG;
//        [imageEditorV setImageUrlArray:@[] imageChange:^(NSInteger suc,CGFloat h) {
//            viewS.contentSize=CGSizeMake(kScreenWidth-1, YH(imageEditorV)>H(viewS)+1?YH(imageEditorV):H(viewS)+1);
//        }];
    }
    NSArray * patharr = [self.otherInfo valueForKey:@"path"];
    
    if (!patharr) {
        
        patharr = [[NSArray alloc]init];
    }
    
    for (NSDictionary*dic in patharr) {

        [self.imageArray addObject:[dic valueForJSONStrKey:@"url"]];
    }
    UIImage * image = [UIImage imageNamed:@"zdyadd"];
    [self.imageArray addObject:image];
    
    EMWeakSelf(weakSelf);
     __weak UIScrollView *viewS=scrollBG;
  
    _imageEditorV.imageArray = self.imageArray;
    [_imageEditorV reshData];
    _imageEditorV.remBlock = ^(NSInteger row) {
        
        
        
        if (weakSelf.pathArray.count > row) {
            
            NSString * idd = [[weakSelf.pathArray[row] valueForJSONStrKey:@"id"] mutableCopy];
            [weakSelf.remArray addObject:idd];
            [weakSelf.pathArray removeObjectAtIndex:row];
        }
        
    };
    _imageEditorV.imageBlock = ^(NSMutableArray *imageArr, CGFloat cH) {
        
        
         weakSelf.imageArray = imageArr;
        
        viewS.contentSize=CGSizeMake(kScreenWidth-1, YH(_imageEditorV)>H(viewS)+1?YH(_imageEditorV) + 10:H(viewS)+1+10);

    };
    
    viewS.contentSize=CGSizeMake(kScreenWidth-1, YH(_imageEditorV)>H(viewS)+1?YH(_imageEditorV) + 10:H(viewS)+1+10);
    
}
-(void)initImagesView{
  
    AddImageView*  imageEditorV = [[AddImageView alloc] initWithFrame:CGRectMake(0, tempY, kScreenWidth, ((self.imageArray.count % 4 == 0?0:1) + self.imageArray.count / 4) * (kScreenWidth - 20)/4)];
    imageEditorV.backgroundColor = [UIColor whiteColor];
    [scrollBG addSubview:imageEditorV];
    _imageEditorV = imageEditorV;
 
}

-(UITextField *)addViewWithFrameY:(float)_fy withTitle:(NSString *)strTitle withSel:(SEL)sel{
    UIView *viewBG=[[UIView alloc] initWithFrame:CGRectMake(0, _fy, kScreenWidth, 44)];
    viewBG.backgroundColor=[UIColor whiteColor];
    [scrollBG addSubview:viewBG];
    
    [viewBG addSubview:[RHMethods labelWithFrame:CGRectMake(10, 0, 160, H(viewBG)) font:fontTitle color:rgbTitleColor text:strTitle]];
    
    //    [viewBG addLineLayerWhitframe:CGRectMake(0, 0, W(viewBG), 0.5) whitColor:rgbLineColor];
    [viewBG addLineLayerWhitframe:CGRectMake(0, 43.5, W(viewBG), 0.5) whitColor:rgbLineColor];
    UITextField *txt=[RHMethods textFieldlWithFrame:CGRectMake(90, 0, W(viewBG)-100, 44) font:fontTitle color:rgbTitleColor placeholder:@"请输入" text:@"" ];
    [txt setTextAlignment:NSTextAlignmentRight];
    txt.delegate=self;
    [viewBG addSubview:txt];
    if (sel) {
        txt.placeholder=@"请选择";
        txt.enabled=NO;
        txt.frameWidth=W(viewBG)-117;
        UIButton *btnSelect=[RHMethods buttonWithFrame:viewBG.bounds title:nil image:@"Righticon070116" bgimage:nil];
        [btnSelect setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
        [btnSelect setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10)];
        [btnSelect addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
        [viewBG addSubview:btnSelect];
    }
    return txt;
}
//获取数据
-(void)makeData{
    
    krequestParam
    [NetEngine createHttpAction:@"products/productscity" withCache:NO withParams:dictparam withMask:SVProgressHUDMaskTypeClear onCompletion:^(id resData, BOOL isCache) {
  
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            
            self.cityList = resData[@"data"][@"list"];
            [self makeUI];
            
            
        }else{
            
  
            
        }
        
    } onError:^(NSError *error) {
        
    }];
    

    
}

#pragma mark button
-(void)subButtonClicked{
    
//    NSString *txtName.text=txtName.text;
//    NSString *txtMoney.text=txtMoney.text;//价格
    //    NSString *strLevle=txtLevle.text;//等级
//    NSString *txtcapital.text=txtcapital.text;//资本
//    NSString *txtCity.text=txtCity.text;
//    NSString *txtAddress.text=txtAddress.text;
//    NSString *txtStartDate.text=txtStartDate.text;
//    NSString *txtEndDate.text=txtEndDate.text;
//    NSString *txtRange.text=txtRange.text;//经营范围
//    NSString *txtadvantage.text=txtadvantage.text;//转让优势
    
    if (![txtshoujiay.text notEmptyOrNull]) {
        [SVProgressHUD showErrorWithStatus:@"请输入售价"];
        
        return;
    }
    
    if (![txtfenlie getAddValueForKey:@"data"]) {
        [SVProgressHUD showErrorWithStatus:@"请选择分类"];
        
        return;
    }
    
    if (![txtLevle getAddValueForKey:@"data"]) {
        [SVProgressHUD showErrorWithStatus:@"请选择等级"];
        
        return;
    }
    
    if (![txtType getAddValueForKey:@"data"]) {
        [SVProgressHUD showErrorWithStatus:@"请选择类型"];
        
        return;
    }
    
    if (![txtName.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入公司名称"];
        return;
    }
    if (![txtMoney.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入结算价格"];
        return;
    }
    if (![txtcapital.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入资本"];
        return;
    }
    if (![txtCity.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"选择注册地址"];
        return;
    }
//    if (![txtAddress.text notEmptyOrNull]) {
//        [SVProgressHUD showImage:nil status:@"请输入详细地址"];
//        return;
//    }
    if (![txtStartDate.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请选择成立时间"];
        return;
    }
    if (![txtEndDate.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请选择到期时间"];
        return;
    }
    if (![txtRange.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入经营范围"];
        return;
    }
    
    krequestParam
    [dictparam setValue:[self.otherInfo valueForJSONStrKey:@"id"] forKey:@"id"];
    [dictparam setValue:txtshoujiay.text forKey:@"price"];
    [dictparam setValue:txtName.text forKey:@"title"];
    [dictparam setValue:txtMoney.text forKey:@"saleprice"];
    [dictparam setValue:[txtfenlie getAddValueForKey:@"data"]  forKey:@"cid"];
//    [dictparam setValue:[dicSelectLevel valueForJSONStrKey:@"id"] forKey:@"level"];
    [dictparam setValue:[txtLevle getAddValueForKey:@"data"]  forKey:@"level"];
    [dictparam setValue:[txtType getAddValueForKey:@"data"]  forKey:@"typeid"];
    
    [dictparam setValue:txtcapital.text forKey:@"regcapital"];
    //    [dictparam setValue:strCity forKey:@"regaddr"];
//    [dictparam setValue:txtAddress.text forKey:@"address"];
    [dictparam setValue:txtStartDate.text forKey:@"regtime"];
    [dictparam setValue:txtEndDate.text forKey:@"expiretime"];
    [dictparam setValue:txtRange.text forKey:@"businessscope"];
    [dictparam setValue:txtadvantage.text forKey:@"advantage"];
    
    
    
//    if ([[dicP3City valueForJSONStrKey:@"areaid"] notEmptyOrNull]) {
//        [dictparam setValue:[dicP3City valueForJSONStrKey:@"areaid"] forKey:@"regaddr"];
//    }else{
//        [dictparam setValue:[dicP2City valueForJSONStrKey:@"areaid"] forKey:@"regaddr"];
//    }
    
    [dictparam setValue:[txtCity getAddValueForKey:@"province"] forKey:@"province"];
    
    [dictparam setValue:[txtCity getAddValueForKey:@"areaid"] forKey:@"areaid"];
    [dictparam setValue:txtCity.text forKey:@"regaddr"];
//    if ([self.userInfo isEqualToString:@"Edit"]  ) {
//        if ( [imageEditorV.arrayDeleteIds count]>0) {
//            [dictparam setValue:[imageEditorV.arrayDeleteIds componentsJoinedByString:@","] forKey:@"pathid"];
//        }
//        [dictparam setValue:[self.otherInfo valueForJSONStrKey:@"id"] forKey:@"id"];
//    }
//    NSArray *arrayImages=[imageEditorV getRequsetArrywithkey:@"path" removeServer:YES];
    
    NSMutableArray * imageArr = [[NSMutableArray alloc]init];
    
    for (int i = 0; i < self.imageArray.count - 1; i ++) {
        
        id image = self.imageArray[i];
        if ([image isKindOfClass:[UIImage class]]) {
            
            [imageArr addObject:image];
            
        }
        
    }
    
    NSMutableArray *fileData = [[NSMutableArray alloc] init];
    for (int i = 0; i < imageArr.count; i++) {
        
        UIImage *image = imageArr[i];
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:UIImageJPEGRepresentation([[Utility Share]imageWithImageSimple:image scaledToSize:CGSizeMake(image.size.width, image.size.height)], 1),@"fileData",@"path[]",@"fileKey",@"aa.jpg",@"fileName",@"image",@"fileType", nil];
        
        [fileData addObject:dic];
    }
     [dictparam setValue:[self.remArray componentsJoinedByString:@","] forKey:@"pathid"];
    
    [NetEngine uploadAllFileAction:XKFV4productsupdateproducts withParams:dictparam fileArray:fileData onCompletion:^(id resData, BOOL isCache) {
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            [self backRefreshData];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [MyUiIAlertView showAlerttWithTitle:[resData valueForJSONStrKey:@"info"] message:nil cancelButtonTitle:@"确定" otherButtonTitles:nil WithAlertBlock:^(UIAlertView * _Nonnull alertView, NSInteger buttonIndex) {
                    
                    _status=200;
                    if (self.allcallBlock) {
                        self.allcallBlock(nil,200,nil);
                    }
                    [super backButtonClicked:nil];
                }];
            });
        }else{
            [SVProgressHUD showImage:nil status:[resData valueForJSONStrKey:@"info"]];
        }
    } onError:^(NSError *error) {
        [SVProgressHUD showImage:nil status:alertErrorTxt];
    } withMask:SVProgressHUDMaskTypeBlack];
    
    
    
}
-(void)selectfenleiButtonClicked{
//    [self pushController:[SellSelectTypeViewController class] withInfo:NSStringFromClass([self class]) withTitle:@"选择等级" withOther:@{@"selectArray":@[[dicSelectLevel valueForJSONStrKey:@"id"]],@"list":[[[Utility Share] userTypeData] objectForJSONKey:@"level"]}];
    
    NSMutableDictionary*mdic=[NSMutableDictionary new];
    [mdic setObject:txtfenlie.text forKey:@"currentTitle"];
    
    NSMutableArray*mtitlarray=[NSMutableArray new];
    
    NSArray*array=[UTILITY.userTypeData objectForKey:@"bigcate"];
    for (NSDictionary*dic in array) {
        for (NSDictionary *subdic in [dic objectForJSONKey:@"list"]) {
            NSMutableDictionary*submdic=[NSMutableDictionary dictionaryWithDictionary:subdic];
            [submdic setObject:[subdic objectForKey:@"name"] forKey:@"title"];
            
            [mtitlarray addObject:submdic];
        }
    }
     [mdic setObject:mtitlarray forKey:@"titleArray"];
      __weak __typeof(txtfenlie) weaktxtfenlie = txtfenlie;
    [self pushController:[SelectTitleViewController class] withInfo:nil withTitle:@"选择分类" withOther:mdic withAllBlock:^(id data, int status, NSString *msg) {
        weaktxtfenlie.text=[data objectForJSONKey:@"title"];
        [weaktxtfenlie setAddValue:[data objectForJSONKey:@"id"] forKey:@"data"];
        
    }];
}
-(void)selectLevleButtonClicked{
//    [self pushController:[SellSelectTypeViewController class] withInfo:NSStringFromClass([self class]) withTitle:@"选择等级" withOther:@{@"selectArray":@[[dicSelectLevel valueForJSONStrKey:@"id"]],@"list":[[[Utility Share] userTypeData] objectForJSONKey:@"level"]}];
    
    
    NSMutableDictionary*mdic=[NSMutableDictionary new];
    [mdic setObject:txtLevle.text forKey:@"currentTitle"];
    
    NSMutableArray*mtitlarray=[NSMutableArray new];
    
    NSArray*array=[UTILITY.userTypeData objectForKey:@"level"];
    for (NSDictionary*subdic in array) {
        //        for (NSDictionary *subdic in [dic objectForJSONKey:@"list"]) {
        NSMutableDictionary*submdic=[NSMutableDictionary dictionaryWithDictionary:subdic];
        [submdic setObject:[subdic objectForKey:@"name"] forKey:@"title"];
        
        [mtitlarray addObject:submdic];
        //        }
    }
    [mdic setObject:mtitlarray forKey:@"titleArray"];
    __weak __typeof(txtLevle) weaktxtLevle = txtLevle;
    [self pushController:[SelectTitleViewController class] withInfo:nil withTitle:@"选择等级" withOther:mdic withAllBlock:^(id data, int status, NSString *msg) {
        weaktxtLevle.text=[data objectForJSONKey:@"title"];
        [weaktxtLevle setAddValue:[data valueForKey:@"id"] forKey:@"data"];
        
    }];
}
-(void)selectTypeButtonClicked{
    NSMutableDictionary*mdic=[NSMutableDictionary new];
    [mdic setObject:txtType.text forKey:@"currentTitle"];
    
    NSMutableArray*mtitlarray=[NSMutableArray new];
    
   NSArray*array=[UTILITY.userTypeData objectForKey:@"types"];
    for (NSDictionary*subdic in array) {
//        for (NSDictionary *subdic in [dic objectForJSONKey:@"list"]) {
            NSMutableDictionary*submdic=[NSMutableDictionary dictionaryWithDictionary:subdic];
            [submdic setObject:[subdic objectForKey:@"name"] forKey:@"title"];
            
            [mtitlarray addObject:submdic];
//        }
    }
    [mdic setObject:mtitlarray forKey:@"titleArray"];
    __weak __typeof(txtType) weaktxtType = txtType;
    [self pushController:[SelectTitleViewController class] withInfo:nil withTitle:@"选择分类" withOther:mdic withAllBlock:^(id data, int status, NSString *msg) {
        weaktxtType.text=[data objectForJSONKey:@"title"];
        [weaktxtType setAddValue:[data valueForJSONKey:@"id"] forKey:@"data"];
        
    }];

}
-(void)selectCityButtonClicked{
    //    [SVProgressHUD showImage:nil status:@"地址"];
    //SelectAddressView
//    if (arrayCity) {
//        if (!selectCity) {
//            selectCity=[[SelectAddressView alloc] init];
//        }
//        selectCity.delegate=self;
//        selectCity.dicP1=dicP1City;
//        selectCity.dicP2=dicP2City;
//        selectCity.dicP3=dicP3City;
//        selectCity.arrayAddress=arrayCity;
//        [selectCity show];
//    }else{
//        [self loadCityData];
//    }
    
    
    [self.view endEditing:YES];
    [QPickerView showQPickerViewWithTitle:@"选择城市" Data:arrayCity dataBlock:^(NSMutableArray *titleArray, NSMutableArray *indexArray, NSMutableArray *indexDataArray) {
        txtCity.text= [titleArray componentsJoinedByString:@" "];
        NSString * areaidStr = @"";
//        for (NSDictionary * dic in indexDataArray) {
//
//            areaidStr = [dic valueForJSONStrKey:@"areaid"];
//
//        }
        
        [txtCity setAddValue:@"" forKey:@"province"];
        [txtCity setAddValue:@"" forKey:@"areaid"];
        for (int i = 0; i < indexDataArray.count; i++) {
            
            NSDictionary * dic = indexDataArray[i];
            if (i ==0) {
                
                 [txtCity setAddValue:[dic valueForJSONStrKey:@"areaid"] forKey:@"province"];
                
            }else if (i ==1){
                
                 [txtCity setAddValue:[dic valueForJSONStrKey:@"areaid"] forKey:@"areaid"];
                
            }
            
            
        }
       
        
    }];
  
    
}
-(void)loadCityData{
    krequestParam
    [NetEngine createPostAction:@"products/productscity" withParams:dictparam onCompletion:^(id resData, BOOL isCache) {
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            arrayCity=[[resData objectForJSONKey:@"data"] objectForJSONKey:@"list"];
            [self selectCityButtonClicked];
        }else{
            [SVProgressHUD showImage:nil status:[resData valueForJSONStrKey:@"info"]];
        }
    }];
    
}
-(void)selectStartDateButtonClicked{
    //选择时间
    [self.view endEditing:YES];
    if (!dateView) {
        dateView=[[SelectDateView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    }
    dateView.strType=@"date";
    dateView.delegate=self;
    [dateView show];
}
-(void)selectEndDateButtonClicked{
    [self.view endEditing:YES];
    //选择时间
    if (!dateView2) {
        dateView2=[[SelectDateView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    }
    dateView2.strType=@"date";
    dateView2.delegate=self;
    [dateView2 show];
}

#pragma mark - keyboak
#pragma mark - keyboak
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //注册监听键盘事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
}


-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}



-(void)handleKeyboardDidShow:(NSNotification *)notification{
    
    NSDictionary *info = [notification userInfo];
    CGRect keyboardFrame;
    [[info objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
    CGFloat distanceToMove = kbSize.height;
    NSLog(@"---->动态键盘高度:%f",distanceToMove);
#pragma mark zxh UI布局 根据键盘布局
    
    if (![self getAddValueForKey:@"scrollViewH"]) {
        [self setAddValue:[NSString stringWithFormat:@"%f",scrollBG.frameHeight] forKey:@"scrollViewH"];
    }
    
    scrollBG.frame=CGRectMake(X(scrollBG), Y(scrollBG), W(scrollBG),self.view.frame.size.height- Y(scrollBG)-distanceToMove);
    
    [WSKeyBoardTool TFscrollview:scrollBG];
    
}
- (void)handleKeyboardWillHide:(NSNotification *)notification
{
    
    [UIView animateWithDuration:0.3 animations:^{
        scrollBG.frame=CGRectMake(0,  Y(scrollBG), kScreenWidth,[[self getAddValueForKey:@"scrollViewH"] floatValue]);
    }];
}//

#pragma mark UITextFieldDelegate,UITextViewDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
#pragma mark SelectDateViewDelegate
-(void)select:(SelectDateView *)sview object:(id)dic{
    // dateTemp=dic;
    if (sview==dateView) {
        selectDate=[NSString stringWithFormat:@"%f",[dic timeIntervalSince1970]];
        txtStartDate.text=[[Utility Share] time_ChangeTheFormat:selectDate];
    }else{
        selectDateEnd=[NSString stringWithFormat:@"%f",[dic timeIntervalSince1970]];
        txtEndDate.text=[[Utility Share] time_ChangeTheFormat:selectDateEnd];
    }
    
}
#pragma mark SelectAddressViewDelegate
-(void)selectPicker:(SelectAddressView *)selectView address1:(id)addres_a address2:(id)address_b address3:(id)address_c{
    dicP1City=addres_a;
    dicP2City=address_b?address_b:@{};
    dicP3City=address_c?address_c:@{};
    txtCity.text=[NSString stringWithFormat:@"%@ %@ %@",[dicP1City valueForJSONStrKey:@"name"],[dicP2City valueForJSONStrKey:@"name"],[dicP3City valueForJSONStrKey:@"name"]];
}

#pragma mark pop
-(void)backRefreshData{
    for (id controller in self.navigationController.viewControllers) {
        if ([NSStringFromClass([controller class]) isEqualToString:@"CRMViewController"]||
            [NSStringFromClass([controller class]) isEqualToString:@"UserLicensePlateViewController"]) {
            if ([(NSObject*)controller respondsToSelector:@selector(popRefreshData)]) {
                [controller performSelector:@selector(popRefreshData) withObject:nil afterDelay:0.01];
            }
            continue;
        }
    }
    
}
-(void)popRefreshType:(NSDictionary *)dic{
    dicSelectLevel=dic;
    txtLevle.text=[dic valueForJSONStrKey:@"name"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSArray *)cityList{
    
    if (!_cityList) {
        _cityList = [[NSArray alloc]init];
        
    }
    
    
    return _cityList;
}
-(NSMutableArray *)imageArray{
    
    if (!_imageArray) {
        
        _imageArray = [[NSMutableArray alloc]init];
    }
    
    return _imageArray;
}
-(NSMutableArray *)pathArray{
    
    if (!_pathArray) {
        
        _pathArray = [[NSMutableArray alloc]init];
    }
    
    return _pathArray;
}
-(NSMutableArray *)remArray{
    
    if (!_remArray) {
        
        _remArray = [[NSMutableArray alloc]init];
    }
    
    return _remArray;
}
@end
